<?php


namespace Api\Controller;

use Api\Event\StatisEvent;
use Common\Util\RSA;
use Think\Log;
// +----------------------------------------------------------------------
// | 文件 StatController.class.php
// +----------------------------------------------------------------------
// | 说明 上报统计
// +----------------------------------------------------------------------
// | 
// +----------------------------------------------------------------------
// | Author: 谢赤心 Legend. <xcx_legender@qq.com>
// +----------------------------------------------------------------------

class StatController extends PublicController 
{

    // 上报设备信息
	public function device()
	{
		$request = file_get_contents('php://input', 'r');
		$request = json_decode($request, true);
		// print_r($request);
		event('statis')->operDevice($request['platform'], $request['mac'], $request['data']);
		$this->success('ok', ['video_scale' => 100]);
	}

    // 上报的
    // public function tool()
    // {
        // $action = I('action');
        // $step   = I('step', 1, 'intval');
        // if (!defined('PLATFORM')) define('PLATFORM', 5);
        // $version = I('version');
        // event('Statis')->operStatisTool($action, $step, ['version' => $version]);
    // }

    // 上报用户行为
    public function user_action()
    {

        $RSA = new RSA(C('RSA_PUBLIC_KEY'), C('RSA_PRIVATE_KEY'));
        $content = file_get_contents("php://input");
        $request = $RSA->privateDecrypt($content)->toJson();
        if (!$request) {
            return $this->error(self::$API_ERROR['SIGN'], 'sign error');
        }
        \Think\Log::record("[STAT-JSON]".json_encode($request),'DEBUG');
        event('Statis')->operUserAction($request);
        $this->success('操作成功');
    }




}